{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def TEDeploy (base, ticker):\n",
    "    ticker = ';'.join(ticker)\n",
    "    url = 'https://api.tradingeconomics.com/historical/ticker/{tick}?client=guest:guest'.format(tick = ticker)\n",
    "    myDF = pd.read_json(url)\n",
    "    myDF['DateTime'] = pd.to_datetime(myDF['DateTime'])\n",
    "    myDF = myDF.set_index('DateTime')\n",
    "    myDF = myDF[['HistoricalDataSymbol', 'Value']]\n",
    "    myDF = myDF.pivot_table(values='Value',\n",
    "                            index=myDF.index,\n",
    "                            columns='HistoricalDataSymbol',\n",
    "                            aggfunc='first')  \n",
    "    startDate = datetime.datetime.today() - relativedelta(years = 5)\n",
    "    myDF = myDF[startDate:]\n",
    "    print myDF\n",
    "    baseCur =  pd.concat([base.get('historical'),base.get('points')])\n",
    "    baseCur.index = pd.to_datetime(baseCur.index)\n",
    "    totalDF = pd.concat([myDF,baseCur], axis = 1)\n",
    "    print totalDF\n",
    "    baseRow = totalDF.tail(4).iloc[[0]]\n",
    "    print baseRow\n",
    "    totalDFPct =  totalDF.pct_change()\n",
    "    del totalDFPct.columns.name    \n",
    "    testDF = totalDFPct.tail(3)\n",
    "    \n",
    "    corrs = totalDF.corr()[base.get('historical').columns]\n",
    "\n",
    "    depl = []\n",
    "    for t in range(len(testDF.index)):\n",
    "        depl.append(corrs.T*testDF['EURUSD'][testDF.index[t]])\n",
    "        depl2 = pd.concat(depl)\n",
    "    depl2.index = testDF.index\n",
    "    totalDFPct = totalDFPct.drop(testDF.index)\n",
    "    totalDFPct = pd.concat([totalDFPct, depl2])\n",
    "    print baseRow\n",
    "    print totalDFPct.tail(4).iloc[[0]]\n",
    "    t = baseRow.append(totalDFPct.loc[totalDFPct.tail(4).index[1]:,])\n",
    "    for i in range(len(t)-1):\n",
    "        t.iloc[[i+1]] = pd.DataFrame(t[i:i+2].sum()).T.values\n",
    "    print t\n",
    "     \n",
    "    return"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
